package com.alibaba.otter.node.common.autoconfigure;


import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;

@Setter
@Getter
@PropertySource(value = "classpath*:otter.properties", factory = OtterPropertySourceFactory.class)
@ConfigurationProperties(prefix = "otter")
public class NodeProperties {

    public static final String DEFAULT_HOME =  System.getProperty("user.dir") + "/../";

    public static final String DEFAULT_HTDOCS = DEFAULT_HOME + "/htdocs";

    public static final String DEFAULT_DOWNLOAD_DIR = DEFAULT_HOME + "/download";

    public static final String DEFAULT_EXTEND_DIR = DEFAULT_HOME + "/extend";

    /**
     * root dir
     */
    private String nodeHome = DEFAULT_HOME;

    /**
     * hot doc dir
     */
    private String htDocDir = DEFAULT_HTDOCS;

    private String downloadDir = DEFAULT_DOWNLOAD_DIR;

    private String extendDir = DEFAULT_EXTEND_DIR;

    private Manager manager = new Manager();


    @Setter
    @Getter
    public static class Manager {

        public static final String DEFAULT_ADDRESS = "127.0.0.1:1099";

        private String  address = DEFAULT_ADDRESS;

    }


    private Zookeeper zookeeper = new Zookeeper();

    private Communication communication = new Communication();



    @Setter
    @Getter
    public static class Communication {

        public static final Integer DEFAULT_PAYLOAD = 8388608;

        public static final Integer DEFAULT_POOL_SIZE = 10;

        public static final Integer DEFAULT_MANAGER_PORT = 1099;

        private Integer payload = DEFAULT_PAYLOAD;

        private Integer poolSize = DEFAULT_POOL_SIZE;

    }


    @Setter
    @Getter
    public static class Zookeeper {

        /**
         * 60s
         */
        public static final Integer DEFAULT_SESSION_TIMEOUT = 60000;

        public static final String DEFAULT_CLUSTER = "localhost:2181";

        private String cluster = DEFAULT_CLUSTER;

        private Integer sessionTimeout = DEFAULT_SESSION_TIMEOUT;
    }


}
